package com.kuaimacode.kframework.api.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kuaimacode.kframework.enums.ProtocolTypeEnum;
import com.kuaimacode.kframework.mybatis.mapper.index.ContentMapper;
import com.kuaimacode.kframework.mybatis.models.index.Content;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 内容表（相关协议、说明、关于我们、客服电话等） 服务实现类
 * </p>
 *
 * @author Bean
 * @since 2019-03-15
 */
@Service
public class ContentService extends ServiceImpl<ContentMapper, Content> {


    /**
     * 查询内容管理信息
     *
     * @return
     */
    public String queryContentInfo(ProtocolTypeEnum typeEnum) {

        QueryWrapper<Content> wrapper = new QueryWrapper<>();
        wrapper.eq("type", typeEnum.getType());
        Content content = baseMapper.selectOne(wrapper);
        if (content != null) {
            return content.getContent();
        }
        return "";
    }


    /**
     * 内容管理查询
     * @return
     */
    public Content findByType(int type){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("type",type);
        Content content = baseMapper.selectOne(queryWrapper);
        return content;
    }

    /**
     * 更新内容信息
     * @param content
     * @return
     */
    public int updateContent(Content content){
        return baseMapper.updateById(content);

    }
}
